package com.xiaoyu.lanling.feature.im.request.flow

import com.xiaoyu.im.request.MessageRequest
import com.xiaoyu.im.request.flow.BaseSendAction
import com.xiaoyu.lanling.feature.chat.model.message.MessageType
import com.xiaoyu.lanling.feature.im.data.IMData

class SendAction : BaseSendAction() {
    override fun beforeSend(request: MessageRequest): MessageRequest {
        checkRisk(request)
        return request
    }

    private fun checkRisk(request: MessageRequest) {
        val messageId = request.pendingMessage.id
        val messageType = request.pendingMessage.payload.messageType
        try {
            when (messageType) {
                MessageType.TYPE_1000_TEXT -> {
                    val content = request.pendingMessage.payload.text
                    IMData.checkContentRiskSync(request.pendingMessage, messageId, messageType, content)
                }
                MessageType.TYPE_1001_IMAGE -> {
                    val content = request.pendingMessage.payload.url
                    IMData.checkContentRiskSync(request.pendingMessage, messageId, messageType, content)
                }
            }
        } catch (e: Throwable) {
            e.printStackTrace()
        }
    }
}